﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.ToString().Trim() == "" || TextBox2.Text.ToString().Trim() == "")
        {
            Response.Write("<script>javascript:alert('请输入完整');history.back();</script>");
            Response.End();
        }
        else
        {
            if (this.DropDownList1.SelectedIndex == 0)
            {


                string SQL = "select * from TB_Admin where UserName='" + this.TextBox1.Text + "' and Password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "管理员";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Response.Redirect("index.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }
            }
            if (this.DropDownList1.SelectedIndex == 1)
            {


                string SQL = "select * from TB_ZhuHu where BianHao='" + this.TextBox1.Text + "' and Password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "住户";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Session["XM"] = dt.Rows[0]["XingMing"].ToString();

                  

                    Response.Redirect("Yindex.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }
            }


            if (this.DropDownList1.SelectedIndex == 2)
            {


                string SQL = "select * from TB_YuanGong where BianHao='" + this.TextBox1.Text + "' and Password='" + this.TextBox2.Text + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Session["cx"] = "员工";
                    Session["UserName"] = this.TextBox1.Text;
                    Session["PWD"] = this.TextBox2.Text;
                    Session["XM"] = dt.Rows[0]["XingMing"].ToString();



                    Response.Redirect("YGindex.aspx");
                }
                else
                {
                    Response.Write("<script>javascript:alert('对不起，用户名或密码不正确!');</script>");
                }
            }


        }

    }
}
